package com.tfswx.jcyw.ruleenginedesigner.service.impl;

import com.tfswx.ruleengine.compute.exception.AppException;
import com.tfswx.ruleengine.compute.util.CommonUtil;
import com.tfswx.jcyw.ruleenginedesigner.dao.GzyqXtGzflMapper;
import com.tfswx.jcyw.ruleenginedesigner.dao.model.GzyqXtGzfl;
import com.tfswx.jcyw.ruleenginedesigner.dto.gzflgl.*;
import com.tfswx.jcyw.ruleenginedesigner.service.GzflService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/5/11
 */
@Service
public class GzflServiceImpl implements GzflService {
    @Resource
    private GzyqXtGzflMapper gzyqXtGzflMapper;

    @Override
    public List<GzflListByXmbmQueryOutputDTO> queryGzflListByXmbm(GzflListByXmbmQueryInputDTO gzflListByXmbmQueryInputDTO) {
        GzyqXtGzfl gzyqXtGzfl = new GzyqXtGzfl();
        BeanUtils.copyProperties(gzflListByXmbmQueryInputDTO, gzyqXtGzfl);
        return gzyqXtGzflMapper.queryGzflListByXmbm(gzyqXtGzfl);
    }

    @Override
    public String addGzfl(GzflAddInputDTO gzflAddInputDTO) {
        GzyqXtGzfl gzyqXtGzfl = new GzyqXtGzfl();
        BeanUtils.copyProperties(gzflAddInputDTO, gzyqXtGzfl);
        gzyqXtGzfl.setGzflbm(CommonUtil.getUuid());
        gzyqXtGzfl.setSfsc("N");
        gzyqXtGzfl.setCjsj(new Date());
        gzyqXtGzfl.setZhxgsj(new Date());
        int insert = gzyqXtGzflMapper.insert(gzyqXtGzfl);
        if (insert == 1) {
            return gzyqXtGzfl.getGzflbm();
        }
        throw new AppException("添加规则分类失败");
    }

    @Override
    public boolean updateGzfl(GzflUpdateInputDTO gzflUpdateInputDTO) {
        GzyqXtGzfl gzyqXtGzfl = new GzyqXtGzfl();
        BeanUtils.copyProperties(gzflUpdateInputDTO, gzyqXtGzfl);
        gzyqXtGzfl.setZhxgsj(new Date());
        int insert = gzyqXtGzflMapper.update(gzyqXtGzfl);
        if (insert == 1) {
            return true;
        }
        throw new AppException("修改规则分类失败");
    }

    @Override
    public boolean deleteGzfl(GzflDeleteInputDTO gzflDeleteInputDTO) {
        GzyqXtGzfl gzyqXtGzfl = new GzyqXtGzfl();
        BeanUtils.copyProperties(gzflDeleteInputDTO, gzyqXtGzfl);
        gzyqXtGzfl.setZhxgsj(new Date());
        int insert = gzyqXtGzflMapper.delete(gzyqXtGzfl);
        if (insert == 1) {
            return true;
        }
        throw new AppException("删除规则分类失败");
    }
}
